package com.shengsiyuan.nio;


import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class NioTest10 {

    public static void main(String[] args) throws Exception {

        RandomAccessFile randomAccessFile = new RandomAccessFile("NioTest", "rw");
        FileChannel fc = randomAccessFile.getChannel();

        /*
         *lock(3,6,true); 3：开始锁的位置  6：锁的长度  true：共享锁（false 排它锁）
         * */
        FileLock fl = fc.lock(3, 6, true);

        System.out.println("vaild" + fl.isValid());
        System.out.println("lock type" + fl.isShared());

        fl.release();

        randomAccessFile.close();
    }
}
